<template>
    <div>
      <!-- 搜索结果页-头部导航 -->
      <div class="search-result-container">
        <!-- 点击实现后退效果 -->
        <van-nav-bar
          title="搜索结果"
          left-arrow
          @click-left="$router.go(-1)"
          fixed
        />
      </div>
      <div >
         <van-list
            v-model="loading"
            :finished="done"
            finished-text="我是有底线的！"
            @load="pullUpLoadMoreFn"
            :immediate-check="false"
            offset="50"
            >
<ArticleItem v-for="obj in resultList" :key="obj.art_id" :artObj="obj"/>
 </van-list>
      </div>
    </div>
</template>

<script>
import { searchResultListAPI } from '@/api/search'
let page = 1
export default {
  data () {
    return {
      resultList: [],
      loading: false,
      done: false
    }
  },
  name: 'SearchResult',
  created () {
    this.getSearchResultList()
  },
  methods: {
    async getSearchResultList () {
      const resp = await searchResultListAPI({
        keyword: this.$route.params.name,
        page: page++
      })
      const { results } = resp.data
      if (results.length < 10) {
        this.done = true
        return
      }
      this.resultList = [...this.resultList, ...results]
      this.loading = false
    },
    pullUpLoadMoreFn () {
      this.getSearchResultList()
    }
  }

}
</script>

<style lang="less" scoped>
.search-result-container {
  padding-top: 46px;
}
/deep/.van-icon{
  color: white;
}
</style>
